package org.tomstools.utils.classsearcher.shell;

import org.tomstools.utils.classsearcher.ClassSearcher;

import java.io.IOException;
import java.util.List;
import java.util.Scanner;


public class ConsoleClassSearcher {
    public static final int MAX_CLASS_NAME_LENGTH = 2048;
    public static final int MAX_DIRECTORY_LENGTH = 4096;

    public static void main(String[] args) throws IOException {
        Scanner input=new Scanner(System.in);
        String className = "";
        String directory = "";
        if (args.length == 0 ){
            System.out.println("可以使用参数： <待搜索的完整类名> <完整搜索目录>");
            System.out.println("=============================================");
            System.out.println("输入待搜索的完整类名：如org.junit.Before或org/junit/Before");
            className = input.next();
        }else{
            className = args[0];
        }

        if(args.length < 2){
            System.out.println("请输入完整搜索目录名：如D:\\");
            directory = input.next();
        }else{
            directory = args[1];
        }
        if (className.trim().isEmpty() || directory.trim().isEmpty()){
            System.out.println("输入的类名或目录名为空");
            System.exit(1);
        }
        System.out.println(String.format("将在%s中搜索类：%s", directory, className));
        List<String> fileNames = ClassSearcher.getInstance().search(directory, className);

        System.out.println("=============================================");
        System.out.println("搜索结果：");
        System.out.println("=============================================");
        for (String fileName : fileNames) {
            System.out.println(fileName);
        }
    }

}
